<%--
  User: Sujan
  Date: Apr 13, 2007
  Time: 2:52:55 PM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ page import="com.scalar.chiptrack.commons.Constants,
                 com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/creditNoteAction.do" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
window.onload = init;
var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }
    function assignDate(passedValue)
    {
        dateElement.value=passedValue;
        window.focus();
    }

    function init()
    {
        qs_1 = new QuickSearch(document.creditNoteForm.customerId, document.creditNoteForm.qs1, false);
    }
    function reset()
    {
        document.creditNoteForm.reset();
        qs_1.resetQuickSearchCntrl();
    }
    function validateForm()
    {
        var form = document.creditNoteForm;
        var pa = document.getElementById( "errors" );
        if(chkDate(form.fromDate.value,'From-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            form.fromDate.focus();
            return false;
        }

        if(chkDate(form.toDate.value,'To-Date','N') == false)
        {
            pa.innerHTML = errMsg;
            form.toDate.focus();
            return false;
        }

        if(form.fromDate.value!='' && form.toDate.value!='')
        {
            if (!validateDateOut(formatDateAsMMDDYYYY(form.fromDate.value),formatDateAsMMDDYYYY(form.toDate.value)))
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                form.toDate.focus();
                return false;
            }
        }
        return true;
    }
    function submitPage()
    {
        var form = document.creditNoteForm;
        if ( validateForm() )
        {
            form.action = "<%=chipTracContext%>/creditNoteAction.do?action=<%=Constants.ACTION_SEARCH%>"
            form.submit();
        }
    }
    function openCreditNoteToView( creditNoteId )
    {
       var newWindow = window.open('creditNoteAction.do?action=<%=Constants.ACTION_VIEW%>&creditNoteId='+creditNoteId,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=600,left=100,top=50,resizable=yes');
  	   newWindow.focus();
    }
</SCRIPT>

<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
    <TR>
	    <TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
	    <!-- Side Navigation start -->
	    <%@include file="/jsp/finance/finance_menu.jsp" %>
	    <!-- end of the side navigations -->
        </TD>
	    <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	    <TD valign="top" width="100%"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	    <BR>
        <html:form action="/creditNoteAction.do" name="creditNoteForm" type="com.scalar.chiptrack.finance.creditNote.forms.CreditNoteForm">
            <input type="hidden" name="isSearchSubmit" value="true">
            <TABLE width="80%" align="center" cellpadding="2" cellspacing="2" border="0">
			    <TR><TD colspan="5" class="NArialW" align="center">Credit/Debit Note Search</TD></TR>
			    <TR><TD colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"/><chiptrack:info styleClass="NArialL"/></TD></TR>
			    <TR><TD colspan='5' class="NArialL"><FONT id="errors" color='FF0000'></font></TD></TR>
                <tr>
                    <td class="NArialL" nowrap>
                        Quick Search Customer:
                    </td>
                    <td class="NArialL">
                        <input type="text" name="qs1" class="txfield" size='12' onkeyup='quickSearch(qs_1)'/>
                    </td>
                    <td width="5%">&nbsp;</td>
                    <td class="NArialL" width='30%'>
                        &nbsp;
                    </td>
                    <td class="NArialL" width='20%'>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td class="NArialL">
                        Customer:
                    </td>
                    <td class="NArialL">
                        <nested:select name="creditNoteForm" property="customerId"  styleClass="txfield">
                            <logic:present name="customers">
                                <html:options collection="customers" property="value" labelProperty="label"/>
                            </logic:present>
                        </nested:select>
                    </td>
                    <td width="5%">&nbsp;</td>
                    <td class="NArialL" width="10%">
                        SO Number:
                    </td>
                    <td class="NArialL" align="left">
                        <nested:text property="salesOrderNo" size="15" styleClass="txfield"/>
                    </td>
            </tr>
            <tr>
			    <td class="NArialL" nowrap>
			        Credit/Debit Note #:
			    </td>
			    <td class="NArialL">
                    <nested:text property="creditNoteNumber" styleClass="txfield"/>
			    </td>
                <td class="NArialL" width="5%">&nbsp;</td>
                <td class="NArialL">Is Credit/Debit:</td>
                <td class="NArialL">
                    <nested:select property="noteType"  styleClass="txfield" >
                        <html:option value="0">All</html:option>
                        <html:option value="Credit"/>
                        <html:option value="Debit"/>
                    </nested:select>
                </td>
            </tr>
            <tr>
                <td class="NArialL">
                       Status:
                </td>
                <td class="NArialL">
                    <nested:select property="status"  styleClass="txfield" >
                        <html:option value="0">All</html:option>
                        <html:option value="APPROVED"/>
                        <html:option value="HOLD"/>
                        <html:option value="CANCELLED"/>
                    </nested:select>
                </td>
                <td class="NArialL">&nbsp;</td>
                <td class="NArialL">&nbsp;</td>
            </tr>
            <tr>
			    <td class="NArialL" nowrap>
			        From-Date:
			    </td>
			    <td class="NArialL">
                    <nested:text property="fromDate" styleClass="txfield" size="12"/>&nbsp;
                    <a href="javascript:openCalendar(document.creditNoteForm.fromDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                </td>
                <td class="NArialL" width="5%">&nbsp;</td>
                <td class="NArialL">To-Date:</td>
                <td class="NArialL">
                    <nested:text property="toDate" styleClass="txfield" size="12"/>&nbsp;
                    <a href="javascript:openCalendar(document.creditNoteForm.toDate)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                                    <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                </td>
            </tr>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
			<tr>
				<td colspan="5" align="center">
                    <a href="javascript:submitPage()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search Credit Note';return true" onmouseout="window.status='';return true" title="Click here to Search Credit Note" alt=""></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				    <a href="javascript:reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
				</td>
			</tr>

			<tr>
                <td colspan='5' class="NArialL">
                    Please <chiptrack:restrictedLink functionality='<%=Functionality.CREDIT_DEBIT_NOTE %>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext+"/creditNoteAction.do?action="+Constants.ACTION_SEARCH_NEW%>'
                                onmouseover="window.status='Click to Create Credit/Debit Note';return true" onmouseout="window.status='';return true">click here</chiptrack:restrictedLink> to create new Credit/Debit Note
                </td>
            </tr>
            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
            <logic:present name="creditNotesList">
            <tr>
                <td colspan="5"  >
                    <table width="100%">
                        <tr bgcolor="#993333">
                            <td align="center" class="NArialL"><font color="#FFFFFF">Credit/Debit Note #</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Sales Order #</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Note Type</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Issue Date</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Customer Name</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Credit/Debit Amount</font></td>
                            <td align="center" class="NArialL"><font color="#FFFFFF">Status</font></td>
                            <td colspan="3" align="center" class="NArialL"><font color="#FFFFFF">Action</font></td>
                        </tr>
                        <logic:iterate id="creditNote"  name="creditNotesList" indexId="idx" type="com.scalar.chiptrack.finance.creditNote.CreditNote">
                            <tr bgcolor='<%=idx.intValue()%2==0 ? "#FFFFEE" : "#DEE1E2"%>' class="NArialL">
                                <td align="center"><bean:write name="creditNote" property="creditNoteNumber"/></td>
                                <td align="center"><bean:write name="creditNote" property="salesOrderNo"/></td>
                                <td align="center"><bean:write name="creditNote" property="noteType"/> Note</td>
                                <td align="center"><bean:write name="creditNote" property="issueDate"/></td>
                                <td align="center"><bean:write name="creditNote" property="customerName"/></td>
                                <td align="right"><bean:write name="creditNote" property="totalAmountAsString"/></td>
                                <td align="center"><bean:write name="creditNote" property="finalStatus"/></td>
                                <td align="center"><a href='javascript:openCreditNoteToView(<%=creditNote.getCreditNoteId()%>)' class="leftsection" onmouseover="window.status='Click here to view credit/debit note';return true" onmouseout="window.status='';return true">View</a></td>
                                <td align="center">
                                    <logic:equal value="HOLD" name="creditNote" property="status">
                                        <chiptrack:restrictedLink functionality='<%=Functionality.CREDIT_DEBIT_NOTE %>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext+"/creditNoteAction.do?action="+Constants.ACTION_MODIFY+ "&creditNoteId=" + creditNote.getCreditNoteId()%>'
                                            onmouseover="window.status='Click here to modify credit/debit note';return true" onmouseout="window.status='';return true">Modify</chiptrack:restrictedLink>
                                    </logic:equal>
                                </td>
                                <td align="center">
                                    <logic:equal value="HOLD" name="creditNote" property="status">
                                        <chiptrack:restrictedLink functionality='<%=Functionality.APPROVE_CREDIT_DEBIT_NOTE %>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext+"/creditNoteAction.do?action="+Constants.ACTION_APPROVED+ "&creditNoteId=" + creditNote.getCreditNoteId()%>'
                                            onmouseover="window.status='Click here to modify credit/debit note';return true" onmouseout="window.status='';return true">Approve</chiptrack:restrictedLink>
                                    </logic:equal>
                                </td>
                            </tr>
                        </logic:iterate>
                    </table>
                </td>
            </tr>
            </logic:present>
        </TABLE>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>